package hot_100;

import java.util.HashSet;

import static java.lang.Math.max;

public class 最长连续序列 {
    public static void main(String[] args) {

    }

    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int ans = 0;
        for (int num : set) {
            if (set.contains(num - 1)) {
                continue;
            }
            int temp = num;
            int cnt = 0;
            while (set.contains(temp)) {
                temp++;
                cnt++;
            }
            ans = Math.max(ans, cnt);
        }
        return ans;
    }
}
